/*
 * 文件名: PerMonthWeekDayDialog.java
 * 版    权：  Copyright PingAn Technology All Rights Reserved.
 * 描    述: [该类的简要描述]
 * 创建人: EX-XUJIAO001
 * 创建时间: 2012-1-18
 * 
 * 修改人：
 * 修改时间:
 * 修改内容：[修改内容]
 */
package app.widget.calendar.dialog;

import android.content.Context;
import android.view.View;
import app.log.APPLog;
import app.widget.BaseDialog;
import app.widget.calendar.dialog.PerMonthWeekDayLinearLayout.OnPerMonthWeekDayListener;


/**
 * @author EX-XUJIAO001
 * @date 2012-1-18
 * @version [Android PABank C01, @2012-1-18]
 * @description 每月每周每天dialog
 */
public class PerMonthWeekDayDialog extends BaseDialog {
	/**
	 * 返回的View
	 */
	private View contentView;
	/**
	 * 上下文
	 */
	private Context context;
	/**
	 * 返回的每
	 */
	private int mPer;
	/**
	 * 返回的结果
	 */
	private int mResult;
	/**
	 * 是否隐藏每日的上午下午
	 */
	private boolean isHideAmpm = false;
	/**
	 * 是不是只有星期一到星期五
	 */
	private boolean isFiveDays = false;

	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param context
	 *            上下文
	 */
	public PerMonthWeekDayDialog(Context context, String title) {
		super(context);
		this.context = context;
		setTitle(title);
		initData();
	}

	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param context
	 *            上下文
	 */
	public PerMonthWeekDayDialog(Context context, String title,
			boolean isHideAmPm) {
		super(context);
		this.context = context;
		this.isHideAmpm = isHideAmPm;
		setTitle(title);
		initData();
	}

	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param context
	 *            上下文 星期一到星期五
	 */
	public PerMonthWeekDayDialog(Context context, boolean isFiveDays,
			String title) {
		super(context);
		this.context = context;
		this.isFiveDays = isFiveDays;
		setTitle(title);
		initData();
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 初始化数据
	 */
	private void initData() {
		PerMonthWeekDayLinearLayout perMonthWeekDayLinearLayout = null;
		if (isHideAmpm) {
			perMonthWeekDayLinearLayout = new PerMonthWeekDayLinearLayout(
					context, isHideAmpm);
		} else if (isFiveDays) {
			perMonthWeekDayLinearLayout = new PerMonthWeekDayLinearLayout(
					isFiveDays, context);
		} else {
			perMonthWeekDayLinearLayout = new PerMonthWeekDayLinearLayout(
					context);
		}

		contentView = perMonthWeekDayLinearLayout;

		perMonthWeekDayLinearLayout
				.setOnPerMonthWeekDayListener(new OnPerMonthWeekDayListener() {

					@Override
					public void onPerMonthWeekDayScrollEnd(boolean scrollState) {
						if (scrollState) {
							setBtn1Enable(false);
							setBtn2Enable(false);
						} else {
							setBtn1Enable(true);
							setBtn2Enable(true);
						}

					}

					@Override
					public void onPerMonthWeekDayScrollChange(int per,
							int result) {

						mPer = per;
						mResult = result;

						APPLog.i("zbkc", "mPer:" + mPer + "mResult:"
								+ mResult);
					}
				});

		setBtn1ClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (onPerMonthWeekDayDialgListener != null) {
					onPerMonthWeekDayDialgListener.onPerMonthWeekChange(mPer,
							mResult);
				}

				PerMonthWeekDayDialog.this.dismiss();
			}
		});

		setBtn2ClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				PerMonthWeekDayDialog.this.dismiss();
			}
		});
	}

	@Override
	public View createContentView() {

		return contentView;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * 
	 * @author EX-XUJIAO001
	 * @version [Android PABank C01, 2012-1-18]
	 */
	public interface OnPerMonthWeekDayDialgListener {
		/**
		 * 
		 * [一句话功能简述]<BR>
		 * [功能详细描述]
		 * 
		 * @param per
		 *            每
		 * @param result
		 *            结果
		 */
		void onPerMonthWeekChange(int per, int result);
	}

	/**
	 * 回调监听
	 */
	private OnPerMonthWeekDayDialgListener onPerMonthWeekDayDialgListener;

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] getter
	 * 
	 * @return OnPerMonthWeekDayDialgListener
	 */
	public OnPerMonthWeekDayDialgListener getOnPerMonthWeekDayDialgListener() {
		return onPerMonthWeekDayDialgListener;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] setter
	 * 
	 * @param onPerMonthWeekDayDialgListener
	 *            回调监听
	 */
	public void setOnPerMonthWeekDayDialgListener(
			OnPerMonthWeekDayDialgListener onPerMonthWeekDayDialgListener) {
		this.onPerMonthWeekDayDialgListener = onPerMonthWeekDayDialgListener;
	}

}
